package com.timebank.score.factory;

import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.score.pojo.entity.ScoreTaskLog;
import com.timebank.score.service.RemoteScoreTaskLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 积分任务记录 服务降级处理
 * @author shiliuyinzhen
 */
@Component
public class RemoteScoreTaskLogFallBackFactory implements FallbackFactory<RemoteScoreTaskLogService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteScoreTaskLogFallBackFactory.class);

    @Override
    public RemoteScoreTaskLogService create(Throwable throwable) {

        log.error("积分任务记录服务调用失败:{}", throwable.getMessage());

        return new RemoteScoreTaskLogService() {
            @Override
            public AjaxResult addScoreTaskLog(ScoreTaskLog scoreTaskLog, String source) {
                return AjaxResult.error("新增任务记录调用失败：{}" + throwable.getMessage());
            }
        };

    }
}
